package cn.supermarket.controller;

import cn.supermarket.pojo.dto.ReturnSimpleDTO;
import cn.supermarket.service.iservice.IReturnGoodsService;
import cn.supermarket.web.JsonResult;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/return/goods")
@Slf4j
@Api(tags = "退货单处理模块")
public class ReturnGoodsController extends BaseController{

    @Autowired
    private IReturnGoodsService returnGoodsService;

    @ApiOperation("添加退货单")
    @GetMapping("/add")
    public JsonResult<String> addReturnGoods(ReturnSimpleDTO returnSimpleDTO){
        returnGoodsService.addReturnGoods(returnSimpleDTO);
        return JsonResult.ok("添加退货单完成!");
    }

    @ApiOperation("修改备注操作")
    @PostMapping("/update/remark")
    @ApiImplicitParams({@ApiImplicitParam(value = "id",name = "id",required = true,dataType = "id"),
            @ApiImplicitParam(value = "备注",name = "remark",required = true,dataType = "String")})
    public JsonResult updateRemark(Long id,String remark){
        returnGoodsService.updateRemark(id,remark);
        return JsonResult.ok("修改完成!");
    }

    @ApiOperation("修改是否显示操作")
    @PostMapping("/update/isDisplay")
    @ApiImplicitParams({@ApiImplicitParam(value = "id",name = "id",required = true,dataType = "id"),
            @ApiImplicitParam(value = "是否显示",name = "isDisplay",required = true,dataType = "int")})
    public JsonResult updateIsDisplay(Long id,Integer isDisplay){
        returnGoodsService.updateIsDisplay(id,isDisplay);
        return JsonResult.ok("修改完成!");
    }

    @ApiOperation("修改是否作废操作")
    @PostMapping("/update/isCancel")
    @ApiImplicitParams({@ApiImplicitParam(value = "id",name = "id",required = true,dataType = "id"),
            @ApiImplicitParam(value = "是否作废",name = "isCancel",required = true,dataType = "int")})
    public JsonResult updateIsCancel(Long id,Integer isCancel){
        returnGoodsService.updateIsCancel(id,isCancel);
        return JsonResult.ok("修改完成!");
    }

    @ApiOperation("根据订单号查询信息")
    @GetMapping("/select/orderId")
    @ApiImplicitParam(value = "订单号",name = "orderId",required = true,dataType = "long")
    public JsonResult getByOrderId(Long orderId){
        returnGoodsService.selectByOrderId(orderId);
        return JsonResult.ok("查询完成,请核对信息!");
    }

    @ApiOperation("根据日期查询信息")
    @GetMapping("/select/date")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiImplicitParam(value = "日期",name = "date",required = true,dataType = "LocalDateTime")
    public JsonResult getByDate(Date date){
        returnGoodsService.selectByDate(date);
        return JsonResult.ok("查询完成,请核对信息!");
    }

    @ApiOperation("根据供货商查询信息")
    @GetMapping("/select/returner")
    @ApiImplicitParam(value = "供货商",name = "returner",required = true,dataType = "String")
    public JsonResult getByReturner(String returner){
        returnGoodsService.selectByReturner(returner);
        return JsonResult.ok("查询完成,请核对信息!");
    }
}
